package com.um.springboot.starter.orm.controller;



import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.orm.entity.*;
import com.um.springboot.starter.orm.manager.BaseTreePlusManager;
import com.um.springboot.starter.orm.params.ListDTO;
import com.um.springboot.starter.orm.params.PageDTO;
import com.um.springboot.starter.orm.service.TreeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 邓南辉
 * 日期 2023/2/6
 * 版权所有 广州优匠科技有限公司
 */
@Validated
public class BaseTreePlusController<M extends BaseTreePlusManager<S, E, D, V,P,L,N>,
        S extends TreeService<N,E>,
        E extends BaseEntity,
        D extends BaseDTO,
        V extends BaseVO,
        P extends PageDTO,
        L extends ListDTO,
        N extends TreeNode> extends BasePlusController<M,S,E,D,V,P,L>{

    @ApiPermission("tree")
    @ApiOperation("树结构")
    @GetMapping("tree/{parentId}")
    public Response<List<N>> getTree(@PathVariable String parentId) {
        return Response.success(manager.getTree(parentId));
    }

    @ApiPermission("delete_node")
    @ApiOperation("删除单个节点")
    @DeleteMapping("node/{id}")
    public Response deleteNode(@PathVariable String id) {
        boolean result = manager.deleteNode(id);
        return result?Response.success():Response.failed();
    }

    @ApiPermission("delete_nodes")
    @ApiOperation("删除多个节点")
    @DeleteMapping("nodes")
    public Response deleteNodes(@ApiParam(value = "删除的id", required = true) @RequestBody List<String> ids) {
        boolean result = manager.deleteNodes(ids);
        return result?Response.success():Response.failed();
    }

    @ApiPermission("move")
    @ApiOperation("移动节点")
    @PutMapping("{id}/move")
    public Response deleteNodes(@PathVariable String id, @RequestParam String parentId) {
        boolean result = manager.moveNode(id,parentId);
        return result?Response.success():Response.failed();
    }

}
